<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 5. Image toolkit</a>
</td><td width="60%">
<p align="center">
=====================================<br />
5.6 Getting the color or transparency of a pixel<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
You can read the colors from an image with :<br />
<p class="code"><pre>
C++ : TCODColor TCODImage::getPixel(int x, int y) const
C   : TCOD_color_t TCOD_image_get_pixel(TCOD_image_t image,int x, int y)
Py  : image_get_pixel(image, x, y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>image</td><td>In the C and python version, the image handler, obtained with the <a href="image_load.html">load</a> function.</td></tr>
<tr><td>x,y</td><td>The pixel coordinates inside the image.<br />0 &lt;= x &lt; width<br />0 &lt;= y &lt; height<br /></td></tr>
</table>
Example :<br />
<p class="code"><pre>
C++ : TCODImage *pix = new TCODImage(80,50);
      TCODColor col=pix->getPixel(40,25);
C   : TCOD_image_t pix = TCOD_image_new(80,50);
      TCOD_color_t col=TCOD_image_get_pixel(pix,40,25);
Py  : pix = litbcod.image_new(80,50)
      col=litbcod.image_get_pixel(pix,40,25)
</pre></p>
<br />
If you have set a key color for this image with <a href="image_blit.html">setKeyColor</a>, or if this image was created from a 32 bits PNG file (with alpha layer), you can get the pixel transparency with :<br />
<p class="code"><pre>
C++ : int TCODImage::getAlpha(int x,int y) const
C   : int TCOD_image_get_alpha(TCOD_image_t image,int x, int y)
Py  : image_get_alpha(image, x, y)
</pre></p>
This function returns a value between 0 (transparent pixel) and 255 (opaque pixel).<br />
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>image</td><td>In the C and python version, the image handler, obtained with the <a href="image_load.html">load</a> function.</td></tr>
<tr><td>x,y</td><td>The pixel coordinates inside the image.<br />0 &lt;= x &lt; width<br />0 &lt;= y &lt; height<br /></td></tr>
</table>
Example :<br />
<p class="code"><pre>
C++ : int alpha=pix->getAlpha(40,25);
C   : int alpha=TCOD_image_get_alpha(pix,40,25);
Py  : alpha=litbcod.image_get_alpha(pix,40,25)
</pre></p><br />
You can also use this simpler version (for images with alpha layer, returns true only if alpha == 0) :<br />
<p class="code"><pre>
C++ : bool TCODImage::isPixelTransparent(int x,int y) const
C   : bool TCOD_image_is_pixel_transparent(TCOD_image_t image,int x, int y)
Py  : image_is_pixel_transparent(image, x, y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>image</td><td>In the C and python version, the image handler, obtained with the <a href="image_load.html">load</a> function.</td></tr>
<tr><td>x,y</td><td>The pixel coordinates inside the image.<br />0 &lt;= x &lt; width<br />0 &lt;= y &lt; height<br /></td></tr>
</table>
Example :<br />
<p class="code"><pre>
C++ : bool transparent=pix->isPixelTransparent(40,25);
C   : bool transparent=TCOD_image_is_pixel_transparent(pix,40,25);
Py  : transparent=litbcod.image_is_pixel_transparent(pix,40,25)
</pre></p>
